package com.exercises;

import java.util.Arrays;


public class Exercise74 {

    public static void main(String[] args) {
        System.out.println(Arrays.binarySearch(new int[]{1, 2, 3, 4, 5, 6}, 6));
    }

    public boolean searchMatrix(int[][] matrix, int target) {
        int row = matrix.length;
        int cloum = matrix[0].length;
        if (row == 0 || cloum == 0) return false;
        for (int i = 0; i < row; i++) {
            int left = matrix[i][0], right = matrix[i][cloum - 1];
            if (left == target || right == target) {
                return true;
            } else if (left < target && right > target) {
                int[] targetArr = matrix[i];
                return Arrays.binarySearch(targetArr, target) > 0;
            }
        }
        return false;
    }

}
